package com.lanou3g.ptp.remind.service.impl;

import org.quartz.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class JobServiceImpl {
    @Autowired
    private Scheduler scheduler;

    public void executeJob(Class jobClass, Long parameter, String cron) throws SchedulerException {
        scheduler.start();
        JobDetail jobDetail = JobBuilder.newJob(jobClass)
                .withIdentity(jobClass.getName())
                .usingJobData("parameter", parameter)
                .build();

        CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule(cron).withMisfireHandlingInstructionDoNothing();

        CronTrigger trigger = TriggerBuilder.newTrigger().withIdentity(jobClass.getName()).withSchedule(scheduleBuilder).build();

        scheduler.scheduleJob(jobDetail,trigger);

    }
}
